<template>
    <view>
        <view v-for="(item,index) in goodsListData" :key="index" @click="handleToInfo(item)">
            <uni-card :is-shadow="false">
                <view class="f_s_18">{{item.bt}}</view>
                <view class=" m_t_5 m_b_5 dis_f_sb_c">
                    <view class="f_s_18 c_red">{{item.money}}元/月</view>
                    <view class="c_9 f_s_14">{{item.createTime.substring(0,10)}}</view>
                </view>
                <view class="dis_f_sb_c">
                    <view class="dis_f_l_c" style="flex: 1">
                        <view class="tag_box">{{item.districts}}</view>
                        <view class="tag_box">{{item.jobBenefits}}</view>
                        <view class="tag_box">{{item.education}}</view>
                    </view>
                    <view v-if="!isMy" @click.stop="handleApply(item)">
                        <u-button type="error" size="small" >申请</u-button>
                    </view>
                </view>
                <u-divider></u-divider>
                <view class="dis_f_l_c">
                    <image src="/static/img/zqy.png" style="width: 50rpx;height: 50rpx;"></image>
                    <view class="f_s_14 c_9 m_l_10">{{item.enterpriseName}}</view>
                </view>
                <view class="m_t_10 c_red" v-if="isMy&&item.shzt==3">
                    <view>驳回原因：{{item.shly||''}}</view>
                </view>
            </uni-card>
        </view>
    </view>
</template>
<script>
import {resumeLibraryApi} from "@/sheep/api";

export default {
    name: "index",
    props: {
        goodsList: {
            type: Array,
            default: []
        },
        isMy: {
            type: Boolean,
            default: false
        }
    },
    data() {
        return {
            goodsListData:this.goodsList||[],
        }
    },
    watch: {
        goodsList(curVal) {
            this.goodsListData=[]
            if (curVal.length>0){
                this.goodsListData = curVal
                for (let i = 0; i <curVal.length; i++) {
                    if (curVal[i].photoUrl){
                        this.goodsListData[i].photoUrl = curVal[i].photoUrl.split(',')[0]
                    }
                }
            }
        }
    },
    methods:{
        handleToInfo(item){
            uni.navigateTo({
                url: '/pages/index/info?goodsId='+item.id
            })
        },
        handleLike(item){
            this.$emit('handleLike',item)
        },
        handleApply(item){
            //二次确认
            let that = this
            uni.showModal({
                title: '提示',
                content: '是否申请该职位',
                success: (res) => {
                    if (res.confirm) {
                        resumeLibraryApi({companyId:item.userId,businessInformationId:item.id}).then(res=>{
                            uni.showToast({
                                title: res.msg,
                                icon: "none",
                                duration: 2000
                            })
                            if (res.code==200){
                                that.$emit('updateData')
                            }
                        })
                    } else if (res.cancel) {
                        console.log('用户点击取消');
                    }
                }
            });

        }
    }
}
</script>

<style scoped lang="scss">
.tag_box{
    background-color: #f5f5f5;
    padding: 10rpx 20rpx;
    border-radius: 10rpx;
    color: #66667C;
    font-size: 28rpx;
    margin-right: 10rpx;
}
</style>
